import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { ServicePrefixEnum } from '@/enums/commonEnum';
import type { AxiosRequestConfig } from 'axios';

const SOCIAL_USER_MODULAR = '/system/social-user';
const AUTH_MODULAR = '/system/auth';

export const Api = {
  SocialBind: {
    url: `${ServicePrefixEnum.BASE}/${SOCIAL_USER_MODULAR}/bind`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  SocialUnbind: {
    url: `${ServicePrefixEnum.BASE}/${SOCIAL_USER_MODULAR}/unbind`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
  SocialAuthRedirect: {
    url: `${ServicePrefixEnum.BASE}/${AUTH_MODULAR}/social-auth-redirect`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
}


// 社交绑定，使用 code 授权码
export const socialBind = (type, code, state) => {
  let params = {
    data: {
      type,
      code,
      state
    }
  }
  return defHttp.request({ ...Api.SocialBind,params})
}

// 取消社交绑定
export const socialUnbind = (type, openid) => {
  let params = {
    data: {
      type,
      openid
    }
  }
  return defHttp.request({ ...Api.SocialUnbind,params})
}

// 社交授权的跳转
export const socialAuthRedirect = (type, redirectUri) => {
  let params = {
    type,
    redirectUri
  }
  return defHttp.request({ ...Api.SocialAuthRedirect,params})
}

// 社交绑定，使用 code 授权码
// export const socialBind = (type, code, state) => {
//   return request.post({
//     url: '/system/social-user/bind',
//     data: {
//       type,
//       code,
//       state
//     }
//   })
// }
//
// // 取消社交绑定
// export const socialUnbind = (type, openid) => {
//   return request.delete({
//     url: '/system/social-user/unbind',
//     data: {
//       type,
//       openid
//     }
//   })
// }
//
// // 社交授权的跳转
// export const socialAuthRedirect = (type, redirectUri) => {
//   return request.get({
//     url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri
//   })
// }
